package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.system.domain.Complaint;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.service.IComplaintService;
import com.ruoyi.system.service.IComplaintchuliService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Complaintchuli;

import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 客户投诉处理 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/complaintchuli")
public class ComplaintchuliController extends BaseController
{
    private String prefix = "system/complaintchuli";
	
	@Autowired
	private IComplaintchuliService complaintchuliService;
	@Autowired
	private IComplaintService complaintService;
	
	@RequiresPermissions("system:complaintchuli:view")
	@GetMapping()
	public String complaintchuli()
	{
	    return prefix + "/complaintchuli";
	}
	
	/**
	 * 查询客户投诉处理列表
	 */
	@RequiresPermissions("system:complaintchuli:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Complaintchuli complaintchuli)
	{
		startPage();
        List<Complaintchuli> list = complaintchuliService.selectComplaintchuliList(complaintchuli);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出客户投诉处理列表
	 */
	@RequiresPermissions("system:complaintchuli:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Complaintchuli complaintchuli)
    {
    	List<Complaintchuli> list = complaintchuliService.selectComplaintchuliList(complaintchuli);
        ExcelUtil<Complaintchuli> util = new ExcelUtil<Complaintchuli>(Complaintchuli.class);
        return util.exportExcel(list, "complaintchuli");
    }
	
	/**
	 * 新增客户投诉处理
	 */
	@GetMapping("/add/{complaintId}")
	public String add(@PathVariable("complaintId") Integer complaintId, ModelMap mmap)
	{
		Complaint complaint = complaintService.selectComplaintById(complaintId);
		mmap.put("complaint",complaint);
		mmap.put("complaintId",complaintId);
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存客户投诉处理
	 */
	@RequiresPermissions("system:complaintchuli:add")
	@Log(title = "客户投诉处理", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Complaintchuli complaintchuli)
	{
		SysUser user = getSysUser();
		complaintchuli.setChuliPersonId(user.getUserId());

		return toAjax(complaintchuliService.insertComplaintchuli(complaintchuli));
	}

	/**
	 * 修改客户投诉处理
	 */
	@GetMapping("/edit/{complaintchuliId}")
	public String edit(@PathVariable("complaintchuliId") Integer complaintchuliId, ModelMap mmap)
	{

		Complaintchuli complaintchuli = complaintchuliService.selectComplaintchuliById(complaintchuliId);
		if(complaintchuli != null){
			Complaint complaint = complaintService.selectComplaintById(complaintchuli.getComplaintId());
			mmap.put("complaint",complaint);
		}

		mmap.put("complaintchuli", complaintchuli);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存客户投诉处理
	 */
	@RequiresPermissions("system:complaintchuli:edit")
	@Log(title = "客户投诉处理", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Complaintchuli complaintchuli)
	{

		return toAjax(complaintchuliService.updateComplaintchuli(complaintchuli));
	}
	
	/**
	 * 删除客户投诉处理
	 */
	@RequiresPermissions("system:complaintchuli:remove")
	@Log(title = "客户投诉处理", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(complaintchuliService.deleteComplaintchuliByIds(ids));
	}
	
}
